import java.util.Scanner;

public class MaxSubSumOfSequence {
    public static int MaxSum(int[] arr)
    {
        int ThisSum, MaxSum, j;
        ThisSum = MaxSum = 0;
        for(j = 0; j < arr.length; j++)
        {
            ThisSum += arr[j];
            if(ThisSum > MaxSum)
                MaxSum = ThisSum;
            else if(ThisSum < 0)
                ThisSum = 0;
        }
        return MaxSum;

    }
    public static void main(String[] args){
        System.out.println("请输入几个数并用逗号间隔：");
        Scanner sc = new Scanner(System.in);
        String str = sc.next().toString();
        String[] arr  = str.split(",");
        int[] b = new int[arr.length];
        for(int j = 0; j<b.length;j++)
            b[j] = Integer.parseInt(arr[j]);
        int max=MaxSum(b);
        System.out.println("子数组之和的最大值为"+max);

    }

}
